#! /home/x_liwei/bin/gawk-4.0.1/bin/awk -f 
@include "/home/x_liwei/global/mywork/EMTO5.70/EMTO-IPG-v0.9.3a/src/toolkit_emto.awk"

BEGIN{
		FS="="
		#if(__Debug__="")__Debug__=0
		__Debug__=0
		cfgPath="/home/x_liwei/global/mywork/EMTO5.70/EMTO-IPG-v0.9.3a/src/atom.cfg"
		latPath=gensub("atom.cfg","getLAT","",cfgPath)
		runPath=gensub("atom.cfg","run","",cfgPath)

		#delete the head part & blank lines of atom.cfg, store in atom.cfg.temp
		command="sed '/\\*/d' "cfgPath" |sed '/^ *$/d'>"cfgPath".temp";system(command)
		for(i=ARGC-1;i>=1;i--)
		{ ARGV[i+1]=ARGV[i] }

		ARGV[1]=cfgPath".temp"
		ARGC=ARGC+1
}
{
		if(ARGIND==1)
		{
				# read atom.cfg.temp store element information in array: atom[element name][line #(1-6)]
				if(FNR%6==1){ele=$1;count=1}else{count++}
				if(FNR%6==2){NZ[ele]=gensub(/ |N.*/,"","g",$2)}#;print "ele="ele,"NZ="NZ[ele]}	
				atom[ele][count]=$0
				#if(FNR%6==1){ele=$1;atom0[ele]=$0}else{atom0[ele]=sprintf(""atom0[ele]"\n%s",$0)}
		}
		else
		{
				dealInput($0,LoopArray)

				if($1~/#+ *.*[eE]nd *of *[Ff]ile.*/)
				{
						corePart()
						nextfile
				}
				 #
		}

		
}
END{
		_message("m","FINISH!")
}
